/*
 * Licensed under the MIT License
 * 
 * Copyright (c) 2011 Kay Kreuning
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * http://code.google.com/p/hyves-as3-sdk/
 */
package nl.hyves.api.methods
{
	import nl.hyves.api.methods.options.SortType;
	import nl.hyves.api.utils.JSONMapper;
	import nl.hyves.api.valueobjects.BirthdayVO;
	import nl.hyves.api.valueobjects.ImageVO;
	import nl.hyves.api.valueobjects.MediaVO;
	import nl.hyves.api.valueobjects.UserVO;

	import com.adobe.cairngorm.contract.Contract;

	public class Users
	{
		public static const GET:String = 'users.get';
		public static const GET_BY_USERNAME:String = 'users.getByUsername';
		public static const GET_FRIENDS_BY_LOGGEDIN_SORTED:String = 'users.getFriendsByLoggedinSorted';
		public static const GET_LOGGEDIN:String = 'users.getLoggedin';
		public static const SEARCH_IN_FRIENDS:String = 'users.searchInFriends';
		{
		JSONMapper.registerMapping('user', UserVO);
			
		JSONMapper.registerMapping('birthday', BirthdayVO);
		JSONMapper.registerMapping('profilepicture', MediaVO);
		JSONMapper.registerMapping('media', MediaVO);
		JSONMapper.registerMapping('icon_small', ImageVO);
		JSONMapper.registerMapping('icon_medium', ImageVO);
		JSONMapper.registerMapping('icon_large', ImageVO);
		JSONMapper.registerMapping('icon_extralarge', ImageVO);
		JSONMapper.registerMapping('image', ImageVO);
		JSONMapper.registerMapping('image_fullscreen', ImageVO);
		JSONMapper.registerMapping('square_large', ImageVO);
		JSONMapper.registerMapping('square_extralarge', ImageVO);
		}
		public static function get(userid:String):IMethod
		{
			Contract.precondition(userid && userid != '');

			return new Method(GET, {userid: userid});
		}

		public static function getByUsername(username:String):IMethod
		{
			Contract.precondition(username && username != '');

			return new Method(GET_BY_USERNAME, {username: username});
		}

		public static function getFriendsByLoggedinSorted(sortType:SortType):IMethod
		{
			Contract.precondition(sortType != null);

			return new Method(GET_FRIENDS_BY_LOGGEDIN_SORTED, {sorttype: sortType.value});
		}

		public static function getLoggedin():IMethod
		{
			return new Method(GET_LOGGEDIN);
		}

		public static function searchInFriends(searchterms:String):IMethod
		{
			Contract.precondition(searchterms && searchterms != '');

			return new Method(SEARCH_IN_FRIENDS, {searchterms: searchterms});
		}
	}
}